package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;

import com.woniu.pojo.MedicineMark;

import com.woniu.service.IMedicineMarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 药品收藏收藏表 前端控制器
 * </p>
 *
 * @author 刘岩
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/medicineMark")
@Api(tags = "药品收藏收藏管理")
public class MedicineMarkController extends BaseController{
    @Autowired
    private IMedicineMarkService medicineMarkService;

    @ApiOperation("查询所有")
    @GetMapping("queryAll")
    public Result queryAll(){
        List<MedicineMark> MedicineMarkList = medicineMarkService.list();
        return toDataResult(MedicineMarkList);
    }

    @ApiOperation("根据ID查询药品收藏")
    @GetMapping("/id/{id}")
    public Result queryById(@PathVariable Long id) {
        MedicineMark MedicineMark = medicineMarkService.getById(id);
        return toDataResult(MedicineMark);
    }

    @ApiOperation("增加药品收藏")
    @PostMapping
    public Result add(@RequestBody MedicineMark MedicineMark){
        boolean flag = medicineMarkService.save(MedicineMark);
        return toResult(flag);
    }
    @ApiOperation("编辑药品收藏")
    @PutMapping
    public Result edit(@RequestBody MedicineMark MedicineMark) {
        boolean flag = medicineMarkService.updateById(MedicineMark);
        return toResult(flag);
    }

    @ApiOperation("根据ID删除药品收藏")
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Long id) {
        boolean flag = medicineMarkService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("批量删除药品收藏")
    @PostMapping("/batch")
    public Result removeBatch(@RequestBody List<Long> ids) {
        boolean flag = medicineMarkService.removeBatchByIds(ids);
        return toResult(flag);
    }


}
